package net.lab1024.sa.admin.module.business.amazon.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.admin.module.business.amazon.dao.AmazonTaskDao;
import net.lab1024.sa.admin.module.business.amazon.domain.entity.AmazonTaskEntity;
import net.lab1024.sa.admin.module.business.amazon.domain.form.AmazonTaskAddForm;
import net.lab1024.sa.admin.module.business.amazon.domain.form.AmazonTaskQueryForm;
import net.lab1024.sa.admin.module.business.amazon.domain.form.AmazonTaskUpdateForm;
import net.lab1024.sa.admin.module.business.amazon.domain.vo.AmazonTaskVO;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 亚马逊采集任务表 Service
 *
 * @Author 秦泽鹏
 * @Date 2025-11-03 20:34:57
 * @Copyright 秦泽鹏
 */

@Service
public class AmazonTaskService {

    @Resource
    private AmazonTaskDao amazonTaskDao;

    /**
     * 分页查询
     */
    public PageResult<AmazonTaskVO> queryPage(AmazonTaskQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<AmazonTaskVO> list = amazonTaskDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(AmazonTaskAddForm addForm) {
        AmazonTaskEntity amazonTaskEntity = SmartBeanUtil.copy(addForm, AmazonTaskEntity.class);
        amazonTaskDao.insert(amazonTaskEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(AmazonTaskUpdateForm updateForm) {
        AmazonTaskEntity amazonTaskEntity = SmartBeanUtil.copy(updateForm, AmazonTaskEntity.class);
        amazonTaskDao.updateById(amazonTaskEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        amazonTaskDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        amazonTaskDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
